//
//  CXDHelper.m
//  LiteraryTune
//
//  Created by 陈雪丹 on 2018/5/19.
//  Copyright © 2018年 cxd. All rights reserved.
//

#import "CXDHelper.h"


/**
 *  检测网络状态
 */
static AFNetworkReachabilityManager *_netManager = nil;

@implementation CXDHelper

+ (void)load {
    [self startNetNoti];
}

+ (void)startNetNoti {
    _netManager = [AFNetworkReachabilityManager managerForDomain:@"www.baidu.com"];
    [_netManager startMonitoring];
}

+ (BOOL)isReachable {
    
    if (![_netManager isReachable]) {
        NSLog(@"网络不可用");
        return false;
    }
    return true;
}
//存储用户登录状态
+ (void)userLoginStatusWithBool:(BOOL)isLogin {
    [[NSUserDefaults standardUserDefaults] setBool:isLogin forKey:UserLoginStatus];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

//获取用户登录状态
+ (BOOL)getUserLoginStatus {
    return [[NSUserDefaults standardUserDefaults] boolForKey:UserLoginStatus];
}

//存储用户是否记录密码
+ (void)rememberPasswordWithResult:(BOOL)isRemember {
    [[NSUserDefaults standardUserDefaults] setBool:isRemember forKey:UserRememberPw];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (BOOL)getRememberPassword {
    return [[NSUserDefaults standardUserDefaults] boolForKey:UserRememberPw];
}

//存储用户账户
+ (void)saveUserAccountWithAccountName:(NSString *)accountName {
    [[NSUserDefaults standardUserDefaults] setObject:accountName forKey:UserAccountNameString];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

//获取用户账户
+ (NSString *)getUserAccountName {
    return [[NSUserDefaults standardUserDefaults] objectForKey:UserAccountNameString];
}


//时间戳转换
+ (NSString *)timeTransferWithTimeString:(NSString *)timeInterval {
    if (timeInterval.length == 0) {
        return @"暂无时间";
    }
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm";
    NSString *dateString = [dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[timeInterval integerValue]]];
    return dateString;
}

@end
